{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "d8aee6c9",
   "metadata": {},
   "source": [
    "---\n",
    "* 日期：2022-10-12\\week05（周三）\n",
    "* 课程：python\n",
    "* 记录人：zeng\n",
    "---\n",
    "\n",
    "# 本周知识点\n",
    "\n",
    "> 1. 有序的数据结构-字符串\n",
    ">>1. 字符串的基本概念（回顾）\n",
    ">>>1. Single quotes: 'allows embedded \"double\" quotes'\n",
    ">>>2. Double quotes: \"allows embedded 'single' quotes\"\n",
    ">>>3. Triple quoted: '''Three single quotes''', \"\"\"Three double quotes\"\"\"\n",
    ">>2. 字符串的性质和方法\n",
    ">2. 有序的数据结构-列表"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e0442201",
   "metadata": {},
   "source": [
    "# 1.字符串的性质和方法\n",
    "\n",
    "* 字符串的性质\n",
    ">1. 字符串的有序性\n",
    ">2. 字符串是有长度的\n",
    ">>1. 使用len()检查字符串的长度\n",
    "\n",
    "* 字符串的基础方法（运算法则）\n",
    ">1. 字符串的取值 :str[index]\n",
    ">2. 字符串的切片：str[start, stop取不到]\n",
    ">3. 字符串的拼接：+\n",
    ">4. in 检查成员是否存在\n",
    "* 字符串的一般方法（function/methods 函数/方法）\n",
    ">1. isdight()\n",
    ">"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "0740caab",
   "metadata": {},
   "outputs": [],
   "source": [
    "text = \"广州南方学院团委\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "143b088d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广'"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "eaf1ae49",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'州'"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "f8630f06",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'委'"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "08adacc6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'团'"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[-2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "4f4f2ea3",
   "metadata": {},
   "outputs": [
    {
     "ename": "IndexError",
     "evalue": "string index out of range",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mIndexError\u001b[0m                                Traceback (most recent call last)",
      "\u001b[1;32m~\\AppData\\Local\\Temp/ipykernel_2584/4266458267.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mtext\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m100\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mIndexError\u001b[0m: string index out of range"
     ]
    }
   ],
   "source": [
    "text[100]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "76e746ba",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "8"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(text)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "efcfa26b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南'"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[0] + text[1] + text[2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "75c5d83c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南方学院'"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[0:6] # 等价于 text[:6]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "c87364f8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南方学院'"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    " text[:6]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "3359b566",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'团委'"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    " text[-2:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "feec276a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南方学院团委广州南方学院团委广州南方学院团委'"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "3 * text #乘法"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3069da29",
   "metadata": {},
   "source": [
    "* in 检查成员是否存在\n",
    "* count() 检查字数出现次数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "0e1d9552",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"广州\" in text"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "b9214405",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"上海\" in text"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "e027be04",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "3 * text.count(\"广州\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "407c89bb",
   "metadata": {},
   "source": [
    "* isdight()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "32b0587f",
   "metadata": {},
   "outputs": [],
   "source": [
    "age_1 = 19\n",
    "age_2 = \"19\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "b44bee54",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "19 <class 'int'>\n",
      "19 <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "print(age_1,type(age_1))\n",
    "print(age_2,type(age_2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "e488a817",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "38\n"
     ]
    }
   ],
   "source": [
    "if age_2.isdigit:\n",
    "    print(age_1 + int(age_2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "7105b4f6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "38"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "age_1 + int(age_2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "9e887e86",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "38\n"
     ]
    }
   ],
   "source": [
    "# 如果字符串是数值，可以用int转换成真正的数值\n",
    "if age_2.isdigit():\n",
    "    print(age_1 + int(age_2))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "34351024",
   "metadata": {},
   "source": [
    "# 2.有序的数据结构-列表（List）\n",
    "\n",
    "* 1. 列表的概念的基本性质\n",
    ">>1. Python knows a number of compound data types, used to group together other values. The most versatile is the list, which can be written as a list of comma-separated values (items) between square brackets. Lists might contain items of different types, but usually the items all have the same type.\n",
    "\n",
    "* 2. 列表的一般方法（如何学习）\n",
    ">1. 使用.Tab键查看列表方法"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "902be55d",
   "metadata": {},
   "source": [
    "# 2.1列表的性质\n",
    "\n",
    "* 和字符串的性质完全一致\n",
    "* 注意；字符串是对字符进行过操作，列表是对items元素进行操作"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "id": "e0174c00",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 4, 9, 16, 25]"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 列表的形式\n",
    "squares = [1, 4, 9, 16, 25] # 列表里面放数值\n",
    "squares"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "id": "7e97d80a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "25"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "squares[4]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "id": "f158a39d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "4 in squares"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "id": "d3bdbbe0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Jack', 'Alex', 'Merry', 'Jan']"
      ]
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names = [\"Jack\",\"Alex\",\"Merry\",\"Jan\"] #列表里面放字符串\n",
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "id": "d2c4e897",
   "metadata": {},
   "outputs": [],
   "source": [
    "info = [\"Jack\",18,\"李华\",20]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "id": "44e9565c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 4, 9, 16, 25, 'Jack', 'Alex', 'Merry', 'Jan']"
      ]
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "squares + names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "id": "e518d514",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 4, 9, 16, 25, 1, 4, 9, 16, 25]"
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "2 * squares"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "id": "0b276e91",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Alex', 'Merry']"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names[1:3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "id": "8bc3f607",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Merry', 'Jan']"
      ]
     },
     "execution_count": 67,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names[-2:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "id": "8b616037",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Jack', 'Merry']"
      ]
     },
     "execution_count": 68,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 取出\"Jack\",\"Jan\"\n",
    "names[:3:2]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d207f815",
   "metadata": {},
   "source": [
    "* 2. 列表的一般方法（如何学习）\n",
    ">1. 增加\n",
    ">2. 删除\n",
    ">3. 改\n",
    ">4. 除\n",
    "* 列表的学习方法（步骤）\n",
    ">1. 使用.Tab键查看列表方法\n",
    ">2. 使用help（查看方法的使用规则）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "id": "b86f8ac4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Jack', 'Alex', 'Merry', 'Jan']"
      ]
     },
     "execution_count": 69,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names = [\"Jack\",\"Alex\",\"Merry\",\"Jan\"] \n",
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "id": "45894d6c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function append:\n",
      "\n",
      "append(object, /) method of builtins.list instance\n",
      "    Append object to the end of the list.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.append)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "id": "017f055a",
   "metadata": {},
   "outputs": [],
   "source": [
    "names.append(\"Lihua\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "id": "362712e0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Jack', 'Alex', 'Merry', 'Jan', 'Lihua']"
      ]
     },
     "execution_count": 72,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names #append 增加内容到list末尾"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "dd6377d7",
   "metadata": {},
   "source": [
    "### 课后作业\n",
    "* 尝试列表的所有方法\n",
    "* 总结列表的方法心得（表格形式总结）\n",
    "\n",
    "| 列表方法 | Description | \texample | 备注 |\n",
    "| --- | --- | --- | --- |\n",
    "| append() | 增加元素，增加在列表的末尾 | names.append(\"zhichao\")， ['Mike', 'Marry', 'Jan', 'Jack', 'zhichao']\t |  |\n",
    "| Paragraph | Text |  |  |"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
